import React, { Component } from 'react';
import { connect } from 'react-redux';
import { user_table } from '../../view_public/Add_public';
import { Table, Tag, Space, Button, Popconfirm } from 'antd';

import { Link } from 'react-router-dom';
import action from '../../../store/action';
import { test } from '../../../store/function';



class index extends React.Component {
    constructor() {
        super();
    }
    componentWillMount() {
        this.Dynamic_get()
    }
    render() {
        const columns = [

            {
                title: '标题',
                dataIndex: 'title',
                key: 'title',
                render: text => <a>{text}</a>,
                width: 230
            },
            {
                title: '创建时间',
                dataIndex: 'createTime',
                key: 'createTime',
                width: 120

            },
            {
                title: '类型',
                dataIndex: 'type',
                key: 'type',
                width: 200,
                render: (record, test) => {
                    switch (record) {
                        case 1:
                            return (<span>动态</span>)
                            break;
                        case 2:
                            return (<span>公告</span>)
                            break;
                        case 3:
                            return (<span>最新数据</span>)
                            break;
                        case 4:
                            return (<span>最新标准</span>)
                            break;
                        case 5:
                            return (<span>最新资源</span>)
                            break;
                        case 6:
                            return (<span>最新案例</span>)
                            break;
                        case 7:
                            return (<span>热门检索</span>)
                            break;
                        case 8:
                            return (<span>材料性能数据</span>)
                            break;
                        case 9:
                            return (<span>测试方法</span>)
                            break;
                        case 10:
                            return (<span>测试规范</span>)
                            break;
                        default:
                            break;
                    }
                }
            },
            {
                title: '操作',
                key: 'action',
                width: 150,
                render: (text, record, index) => {
                    return <Space size="middle">
                        <Link to='/admin/Dynamic_edit'><Button type='link' onClick={() => this.handelLink(record)}>编辑</Button></Link>
                        <Popconfirm
                            title="确定要删除吗？"
                            okText="确定"
                            cancelText="取消"
                            onConfirm={() => this.handleDelete(record.id)}
                        >
                            <Button type="link" danger style={{ padding: "0" }}>
                                删除
                          </Button>
                        </Popconfirm>
                    </Space>
                },
            },

        ]
        const data = this.props.dynamicData;
        return <div>
            {
                user_table(columns, data)
            }
        </div>
    }
    Dynamic_get = () => {
        this.$axios.get('/manager/api/pageGetDynamicAnnouncement/0/9999').then((res) => {
            if (res.status === 1) {
                const { dynamic_get } = this.props;
                let new_list = {};
                [].push.apply(new_list, res.dynamicAnnouncementList);
                dynamic_get(new_list)
            }

        }).catch((err) => {
            console.log(err);
        })
    }
    handelLink = (e) => {

        const { dynamic_edit, edit_falseImg } = this.props;
        dynamic_edit(e)
        edit_falseImg()
    }
    handleDelete = (val) => {

        this.$axios.get(`/manager/api/deleteDynamicAnnouncement/${val}`).then((res) => {
            if (res.status === 1) {
                this.Dynamic_get()
            }

        }).catch((err) => {
            console.log(err);
        })
    }
}

export default connect(state => ({ ...state.custom }), action.custom)(index);